// 临时存储 避免重复请求
import { Local, Session } from "@/utils/storage";
import { getSystemInfoConfig } from "@/api/system/config";

export const globalConfigInfoKey = "globalConfigInfo";
/**
 * 获取系统配置
 * @returns {Promise<void>}
 */
export const loadSystemConfig = async () => {
  let globalConfigInfo = Session.get(globalConfigInfoKey);
  if (!globalConfigInfo) {
    let res = await getSystemInfoConfig();
    Session.set(globalConfigInfoKey, res.data);
    Local.set(globalConfigInfoKey, res.data);
  }
};

export const getSystemConfig = (): SystemConfig => {
  return Local.get(globalConfigInfoKey);
};

export interface SystemConfig {
  casServerUrl: string;
  casServerLoginUrl: string;
  casServerLogoutUrl: string;
  appServerUrl: string;
  appLoginUrl: string;
  webUrl: string;
  enabledCas: boolean;
  logo: string;
  name: string;
  logoImg: string;
  copyright: string;
  webBaseUrl: string;
  sensitiveWord: boolean;
  backgroundImage: string;
  allowThirdPartyLogin: boolean;
  thirdPartyLoginTypeList: string[];
  aMap: AMap;
  oauth2AuthorizeUrl: string;
  cpWxAutoLogin: boolean;
}

interface AMap {
  key: string;
  securityJsCode: string;
}
